package com.eight.cloud.mybatisflex.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.core.activerecord.Model;
import com.mybatisflex.core.keygen.KeyGenerators;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.LocalDateTimeTypeHandler;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @ClassName: BaseEntity
 * @Author: TXC
 * @Date: 2025-09-15 16:37
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseEntity<T extends BaseEntity<T>> extends Model<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @Id(value = "id", keyType = KeyType.Auto)
    private Long id;
    /**
     * 数据编码
     */
    @Id(value = KeyGenerators.flexId, keyType = KeyType.Generator)
    private String uuid;
    /**
     * 创建时间
     */
    @Column(value = "create_time", onInsertValue = "now()", typeHandler = LocalDateTimeTypeHandler.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @Column(value = "update_time", onInsertValue = "now()", onUpdateValue = "now()", typeHandler = LocalDateTimeTypeHandler.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime updateTime;
    /**
     * 创建者
     */
    @Column(value = "create_by")
    private String createBy;
    /**
     * 更新者
     */
    @Column(value = "update_by")
    private String updateBy;
    /**
     * 逻辑删除
     */
    @Column(value = "deleted", onInsertValue = "0", isLogicDelete = true)
    private Integer deleted;

    /**
     * 状态
     */
    private Integer status;


}
